package com.example.yuejian23.yuejian_23.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextClock;
import android.widget.TextView;

import com.example.yuejian23.yuejian_23.Data.Mdata;
import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.javaBean.GerenBean;
import com.example.yuejian23.yuejian_23.javaBean.UserBean;
import com.example.yuejian23.yuejian_23.service.UserService;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class GerenActivity extends AppCompatActivity {
    String userid;
    ImageView touxiang;
    TextView nichen,tel;
    Button xiugai;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_geren);

        initView();

        initEvents();
        geren();

    }


    private void initView() {
        nichen=(TextView)findViewById(R.id.nichen);
        tel=(TextView)findViewById(R.id.tel);
        xiugai=(Button)findViewById(R.id.xiugai);



        touxiang=(ImageView)findViewById(R.id.touxiang);

    }
    private void initEvents() {



    }
    private void geren() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://115.159.93.244/new18yuejian/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        UserService userService=retrofit.create(UserService.class);
        Call<GerenBean> call = userService.getuserinfo(Mdata.uid);;
        call.enqueue(new Callback<GerenBean>() {


            @Override
            public void onResponse(Call<GerenBean> call, Response<GerenBean> response) {
                final GerenBean geren=response.body();
                nichen.setText(geren.getUname());
                tel.setText(geren.getUtel());
                xiugai.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent();
                        intent.putExtra("userid",geren.getUid());
                        intent.setClass(GerenActivity.this,XiugaiGerenActivity.class);
                        startActivity(intent);
                    }
                });
                Picasso.with(GerenActivity.this).load("http://115.159.93.244/new18yuejian/Public/upload/"+geren.getUserpic()).into(touxiang);
            }

            @Override
            public void onFailure(Call<GerenBean> call, Throwable t) {
                System.out.print(toString());
            }
        });
    }
}
